<template>
    <div class="app-container calendar-list-container">
    <!-- filter 条件查询 -->
    <div class="filter-container">
      <el-input
            clearable
            v-model="listQuery.sectionNo"
            :style="searchInputStyle"
            class="filter-item"
            placeholder="请输入工段编号"
      ></el-input>
      <el-input
            clearable
            v-model="listQuery.machineId"
            :style="searchInputStyle"
            class="filter-item"
            placeholder="请输入机台号"
      ></el-input>
      <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <!-- table 表格 -->
    <el-table  :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="机台类型"  prop="machineType"   align="center"/>
      <el-table-column label="机台编号"  prop="machineId"   align="center"/>
      <el-table-column  label="部门" prop='department' align="center" width="100px"/>
      <el-table-column  label="职级" prop='jobClass' align="center"/>
      <el-table-column  label="工段编号" prop='sectionNo' align="center"/>
      <el-table-column  label="面积单价" prop='danjia' align="center"/>
      <el-table-column  label="保护个数单价" prop='danjia2' align="center"/>
      <el-table-column  label="保护面积单价" prop='danjia3' align="center"/>
      <!-- 对员工数据进行编辑与删除操作 -->
      <el-table-column  label="操作"  align="center" width="100"  v-if="userInfo.roleId != 37">
        <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
   
   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

        <!-- 维护工资信息弹出表单 -->
    <el-dialog title="维护工资信息维护" :visible.sync="dialogFormVisible" width="700px">
    <el-form :model="modifyform">
      <el-form-item label="工段编号" :label-width="formLabelWidth">
        <el-input v-model="modifyform.sectionNo" style="width:400px" disabled/>
      </el-form-item>
      <el-form-item label="机器编号" :label-width="formLabelWidth">
        <el-input v-model="modifyform.machineId" :disabled="true" style="width:400px" />
      </el-form-item>
      <el-form-item label="机器名称" :label-width="formLabelWidth" >
        <el-input v-model="modifyform.machineName" style="width:400px" disabled />
      </el-form-item>
      <el-form-item label="机台类型" :label-width="formLabelWidth">
        <el-select v-model="modifyform.machineType" placeholder="请选择机台类型" style="width:400px" disabled>
          <el-option :value="item" :label="item" v-for="(item,index) in this.belongList" :key="index"/>
        </el-select>
      </el-form-item>
      <el-form-item label="面积单价" :label-width="formLabelWidth">
        <el-input v-model="modifyform.danjia" style="width:400px" />
      </el-form-item>
      <el-form-item label="保护个数单价" :label-width="formLabelWidth">
        <el-input v-model="modifyform.danjia2" style="width:400px" />
      </el-form-item>
      <el-form-item label="保护面积单价" :label-width="formLabelWidth">
        <el-input v-model="modifyform.danjia3" style="width:400px" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="modifyMachine">确 定</el-button>
    </div>
    </el-dialog>

  </div>
</template>

<script>
import { machinePage, updateMachine } from '../../api/machine'
export default {
    name: 'ptMaintainsalary',
    data () {
        return {
            listQuery: {
                sectionNo: '',                              //工段编号
                machineId: '',                              //机台号
                page: 1,                                    //页码
                limit: 10,                                   //每页多少条记录
                department: '喷涂车间'
            },
            modifyform: {
                sectionNo: '',                              //工段编号
                machineId: '',                              //机台号
                machineName: '',                            //机台名
                machineType: '',                           //机台类型
            },
            formLabelWidth: '100px',
            searchInputStyle: 'width: 150px;margin-right:15px;',
            total: '',                                      //数据的总数
            tableInfo: '',
            dialogFormVisible: false,
            belongList:['装配','数冲','折弯','钳铆','人工焊组','机器人组','打磨组','喷涂一线','喷涂二线','喷涂三线','喷涂样品线','走芯机','CNC','其他'],
            loadingList: false,
            props: { multiple: true },
            userInfo: this.$store.state.user.userInfo,
        }
    },
    methods: {
        async handleFilter() {
            this.loadingList = true
            let query = Object.assign({},this.listQuery)
            query.isSpray = true
            let {data} = await machinePage(query)
            this.total = data.total
            this.tableInfo = data.records
            this.loadingList = false
        },
        handleEdit(item) {
            this.modifyform = Object.assign({},item)
            this.dialogFormVisible = true
        },
        // 将弹框修改后的工段信息传入后台，并且消息提示是否修改成功
        async modifyMachine() {
            this.dialogFormVisible = false
            let query = Object.assign({},this.modifyform)
            if(query.danjia){ query.danjia = parseFloat(this.modifyform.danjia) }
            else { query.danjia = 0 }
            if(query.danjia2){ query.danjia2 = parseFloat(this.modifyform.danjia2) }
            else { query.danjia2 = 0 }
            if(query.danjia3){ query.danjia3 = parseFloat(this.modifyform.danjia3) }
            else { query.danjia3 = 0 }
            query.isSpray = true
            const data = await updateMachine(query)
            if(data.code == '1'){
                this.$message({
                  message: '修改成功',
                  type: 'success'
              })
              this.handleFilter()
            } else {
              this.$message({
                  message: '修改失败',
                  type: 'warning'
              })
          }
        },
        // table表单下方的页码组件改变每页显示的数据条数
        handleSizeChange(val) {
			this.listQuery.limit = val
			this.handleFilter()
        },
        // table表单下方的页码组件改变页面
        handleCurrentChange(val) {
			this.listQuery.page = val
			this.handleFilter()
        }
    },
    // 进入页面获取table信息
    mounted() {
        this.handleFilter()
    }
}
</script>

<style>

</style>